"use strict";

var path = require("path");
var neat = require('node-neat').includePaths;
var gulp = require("gulp");

var base = path.join(__dirname, "..", "src", "stylesheets", "base.scss");
var source = path.join(__dirname, "..", "src", "stylesheets", "*.scss");
var bundle = "bundle.css";
var build = "./build";

/**
 * Compile scss from source to build.
 * Will generate sourcemaps.
 * Autoprefixer is set to: last 2 version.
 *
 * @method sass
 */
function sass() {
  var plugins = this.opts.plugins;
  return gulp.src(base)
    .pipe(plugins.plumber({
      errorHandler: function(err) {
        plugins.util.log(["sass"], err);
      }
    }))
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.sass({
      includePaths: [source].concat(neat),
      precision: 10
    }))
    .pipe(plugins.autoprefixer({
      browser: ["last 2 version"]
    }))
    .pipe(plugins.sourcemaps.write("."))
    .pipe(plugins.rename(bundle))
    .pipe(gulp.dest(build));
}
module.exports = sass;
